package com.ruoyi.guestInfo.controller;

import java.io.IOException;
import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.guestInfo.domain.WdmGuest;
import com.ruoyi.guestInfo.service.IWdmGuestService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;
import org.springframework.web.multipart.MultipartFile;

/**
 * 顾客信息表Controller
 * 
 * @author lql
 * @date 2025-05-04
 */
@RestController
@RequestMapping("/guestInfo/guest")
public class WdmGuestController extends BaseController
{
    @Autowired
    private IWdmGuestService wdmGuestService;

    /**
     * 查询顾客信息表列表
     */
    @PreAuthorize("@ss.hasPermi('guestInfo:guest:list')")
    @GetMapping("/list")
    public TableDataInfo list(WdmGuest wdmGuest)
    {
        startPage();
        List<WdmGuest> list = wdmGuestService.selectWdmGuestList(wdmGuest);
        return getDataTable(list);
    }

    /**
     * 导出顾客信息表列表
     */
    @PreAuthorize("@ss.hasPermi('guestInfo:guest:export')")
    @Log(title = "顾客信息表", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, WdmGuest wdmGuest)
    {
        List<WdmGuest> list = wdmGuestService.selectWdmGuestList(wdmGuest);
        ExcelUtil<WdmGuest> util = new ExcelUtil<WdmGuest>(WdmGuest.class);
        util.exportExcel(response, list, "顾客信息表数据");
    }
    /**
     * 导入顾客信息列表
     */
    // 权限注解
    @PreAuthorize("@ss.hasPermi('guestInfo:guest:add')")
    // 日志注解
    @Log(title = "顾客信息表", businessType = BusinessType.IMPORT)
    @PostMapping("/import")
    public AjaxResult excelImport(MultipartFile file) throws Exception {
        ExcelUtil<WdmGuest> util = new ExcelUtil<>(WdmGuest.class);
        List<WdmGuest> wdmGuestList = util.importExcel(file.getInputStream());

        return toAjax(wdmGuestService.insertWdmGuestBatch(wdmGuestList));
    }

    /**
     * 获取顾客信息表详细信息
     */
    @PreAuthorize("@ss.hasPermi('guestInfo:guest:query')")
    @GetMapping(value = "/{guestId}")
    public AjaxResult getInfo(@PathVariable("guestId") Long guestId)
    {
        return success(wdmGuestService.selectWdmGuestByGuestId(guestId));
    }

    /**
     * 新增顾客信息表
     * @Validated 用于正则检测
     */
    @PreAuthorize("@ss.hasPermi('guestInfo:guest:add')")
    @Log(title = "顾客信息表", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@Validated @RequestBody WdmGuest wdmGuest)
    {
        return toAjax(wdmGuestService.insertWdmGuest(wdmGuest));
    }

    /**
     * 修改顾客信息表
     */
    @PreAuthorize("@ss.hasPermi('guestInfo:guest:edit')")
    @Log(title = "顾客信息表", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@Validated @RequestBody WdmGuest wdmGuest)
    {
        return toAjax(wdmGuestService.updateWdmGuest(wdmGuest));
    }

    /**
     * 删除顾客信息表
     */
    @PreAuthorize("@ss.hasPermi('guestInfo:guest:remove')")
    @Log(title = "顾客信息表", businessType = BusinessType.DELETE)
	@DeleteMapping("/{guestIds}")
    public AjaxResult remove(@PathVariable Long[] guestIds)
    {
        return toAjax(wdmGuestService.deleteWdmGuestByGuestIds(guestIds));
    }
}
